package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController //组合注解@ResponseBody + @Controller  @ResponseBody 返回json数据 可以把数据直接显示到页面
@RequestMapping("admin/product/")

public class ManageController {

    @Autowired
    private ManageService manageService;

    //http://localhost/admin/product/getCategory1
    @GetMapping("getCategory1")
    public Result getCategory1(){
        //调用服务层
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        //返回数据
        return Result.ok(baseCategory1List);
    }
    //根据一级分类id查询二级数据
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        //调用服务层
        List<BaseCategory2> baseCategory2List = this.manageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }
    //根据一级分类id查询二级数据
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        //调用服务层
        List<BaseCategory3> baseCategory3List = this.manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }
    //根据分类Id 获取平台属性数据
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List> getAttrInfoList(@PathVariable Long category1Id,
                                        @PathVariable Long category2Id,
                                        @PathVariable Long category3Id){
        //调用服务层方法
        List<BaseAttrInfo> baseAttrInfoList = this.manageService.getAttrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }
    /*
    * @RequestBody:
    * */
    //保存平台属性
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        //调用服务层方法
        this.manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    //根据平台属性id回显平台属性值
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        //调用服务层方法
        List<BaseAttrValue> baseAttrValueList = this.manageService.getAttrValueList(attrId);
        return Result.ok(baseAttrValueList);
    }
}
